package mz.matafe.bolao

import grails.test.*

/**
 * Unit Test Class for a Group.
 *
 * @since 0.0.1
 * @author <a href="mailto:matafe@gmail.com">Maurício T. Ferraz</a>
 */
class GroupTests extends GrailsUnitTestCase {

    def group

    protected void setUp() {
        super.setUp()
        // Set up default group
        group = new Group(name: 'A')
        mockForConstraintsTests(Group, [group])
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testToString() {
        assertEquals 'A', group.toString()
    }

    /**
     * Testing the nullable constraints
     */
    void testConstraintsNullable() {
        group = new Group()
        assertFalse group.validate()
        assertEquals 1, group.errors.errorCount
        assertEquals 'The name is null','nullable', group.errors['name']
        group = new Group(name: 'B')
        assertTrue group.validate()
    }

    /**
     * Testing the unique constraints
     */
    void testConstraintsUnique() {
        group = new Group(name: 'A')
        assertFalse group.validate()
        assertEquals 'The name must be unique', 'unique', group.errors['name']
        group = new Group(name: 'B')
        assertTrue group.validate()
    }

    /**
     * Testing the blank constraints
     */
    void testConstraintsBlank() {
        group = new Group(name: '')
        assertFalse group.validate()
        assertEquals 1, group.errors.errorCount
        assertEquals 'The name is blank','blank', group.errors['name']
        group = new Group(name: 'B')
        assertTrue group.validate()
    }

    /**
     * Testing the size constraints
     */
    void testConstraintsMaxSize() {
        group = new Group(name: 'BB')
        assertFalse group.validate()
        assertEquals 'The name has more than 1 characters','maxSize', group.errors['name']
        group.name = 'B'
        assertTrue group.validate()
    }

}